package com.taxi;

import java.net.URL;

import org.apache.pivot.beans.BXML;
import org.apache.pivot.beans.Bindable;
import org.apache.pivot.collections.Map;
import org.apache.pivot.util.Resources;
import org.apache.pivot.wtk.Alert;
import org.apache.pivot.wtk.Frame;
import org.apache.pivot.wtk.MessageType;
import org.apache.pivot.wtk.TabPane;

import com.taxi.service.TaxiService;

public class MainController extends Frame implements Bindable{

    @BXML public NewDriverController newDriverController;
    @BXML public TabPane parentTabPane;
    
    @SuppressWarnings("unused")
    private TaxiService taxiService;
    
    @Override
    public void initialize(Map<String,Object> namespace, URL location, Resources resources) {
        
    }
    
    public void openNewDriverTab() {
        try {
            if (parentTabPane.getTabs().indexOf(newDriverController) != -1) {
                parentTabPane.getTabs().remove(newDriverController);
                return;
            }
            parentTabPane.getTabs().add(newDriverController);
        } catch (Exception e) {
            e.printStackTrace();
            Alert.alert(MessageType.INFO, "Error Occured, please inform support: " + e.getMessage(), Main.mainController);
        }
    }
    

    /**
     * @param taxiService the taxiService to set
     */
    public void setTaxiService(TaxiService taxiService) {
        this.taxiService = taxiService;
        newDriverController.setTaxiService(taxiService);
    }
}
